home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / archiver / zipv107.zip / ZIPV.ASM < prev    next >
Assembly Source File  |  1989-03-16  |  25KB  |  1,047 lines

  1.     page    74,132
  2.     title    ZIPV - Display directory of ZIP files
  3.  
  4. ; name:     ZIPV, version 1, 7 March 1989
  5. ; copyright:    1989, for personal use only; may not be sold.
  6. ; author:    Vernon D. Buerg
  7. ;
  8. ; syntax:
  9. ;        ZIPV [filespec[.ZIP] [/p] [/b] [/c]
  10. ; where:
  11. ;    /p  pauses the display after a screen full
  12. ;    /b  suppresses display of d:\path information for bbs use
  13. ;    /c  displays ZIPfile and file comments and extra fields
  14. ;
  15. ; output:
  16. ;    - errorlevel returned:
  17. ;    0 - normal completion
  18. ;    1 - wrong DOS version
  19. ;    2 - no files found
  20. ;    3 - some invalid ZIP file(s) encountered
  21. ;
  22. ; notes:
  23. ;    - supports DOS 3 file sharing
  24. ;    - requires about 56k of memory, figure 64k for a .COM program
  25. ;    - assembled using SLR Systems OPTASM; you figure the JMPs for MASM
  26. ;    - handles self-extracting ZIP files (.EXE type)
  27.  
  28.     .xlist
  29. print    macro    name            ; display a field
  30.     mov    dx,offset name
  31.     call    prints
  32.     endm
  33.  
  34. printl    macro    text            ; display a literal
  35.     local    txt,nxt
  36.     mov    dx,offset txt
  37.     call    prints
  38.     jmp    nxt
  39. txt    db    cr,lf,text
  40.     db    stopper
  41. nxt    equ    $
  42.     endm
  43.  
  44. save    macro    reglist         ; save registers
  45.     irp    reg, <reglist>
  46.     push    reg
  47.     endm
  48.     endm
  49.  
  50. restore macro    reglist         ; restore registers
  51.     irp    reg, <reglist>
  52.     pop    reg
  53.     endm
  54.     endm
  55.     .list
  56.  
  57. central_dir    struc            ; from APPNOTES.TXT
  58. cd_sig        db    02h,01h,4bh,50h ; signature
  59. cdver_made    db    0,0        ; version made by
  60. cdver_ext    db    0,0        ; version to extract
  61. cd_flag     db    0,0        ; general purpose bit flag
  62. cd_method    dw    0        ; compression method
  63. cd_mod_time    dw    0        ; last mod time
  64. cd_mod_date    dw    0        ; last mod date
  65. cd_crc        dw    0,0        ; crc-32
  66. cd_comp_size    dw    0,0        ; compressed size
  67. cd_true_size    dw    0,0        ; uncompressed size
  68. cd_flnm_len    dw    0        ; filename length
  69. cd_extra_len    dw    0        ; extra field length
  70. cd_comment_len    dw    0        ; file comment length
  71. cd_disk_start    dw    0        ; disk number start
  72. cd_intfile_attr dw    0        ; internal file attributes
  73. cd_extfile_attr dw    0,0        ; external file attributes
  74. cd_local_offset dw    0,0        ; file offset of local header
  75.                     ; variable length fields follow (boo-hiss)
  76. central_dir    ends
  77.  
  78. cd_filename    equ    size central_dir; filename (variable size)
  79. cd_extra    equ    size central_dir; extra field (variable size)
  80. cd_comment    equ    size central_dir; file comment (variable size)
  81.  
  82. central_end    struc            ; length 22+n
  83. ce_sig        db    06h,05h,4bh,50h ; signature
  84. ce_disk_number    dw    0        ; number of this disk
  85. ce_disk_start    dw    0        ; disk number with central dir start
  86. ce_disk_entries dw    0        ; entries in central dir on this disk
  87. ce_entries    dw    0        ; total entries in central dir
  88. ce_size     dw    0,0        ; size of central dir
  89. ce_offset    dw    0,0        ; offset to central dir on this disk
  90. ce_comment_len    dw    0        ; length of zipfile comment
  91.                     ; variable length fields follow (nerts)
  92. central_end    ends
  93.  
  94. ce_comment    equ    size central_end; zipfile comment (variable size)
  95.  
  96. dtantry struc                ; DOS Data Transfer Area
  97. dtarsvd db    21 dup (0)        ;  reserved
  98. dtaattr db    0            ;  attribute
  99. dtatime dw    0            ;  update time
  100. dtadate dw    0            ;  update date
  101. dtasize dw    0,0            ;  size bytes (lo,hi)
  102. dtaname db    12 dup (' ')            ;  name and ext
  103.     db    0,13,10,255        ;  stopper and print
  104. dtantry ends
  105.  
  106.     subttl    ZIPV - Mainline routines
  107.     page
  108.  
  109. cseg    segment public para 'CODE'
  110.     assume    cs:cseg, ds:cseg, ss:cseg, es:cseg
  111.     org    100h
  112.  
  113. zipv    proc    far
  114.     jmp    start            ; skip around data
  115.  
  116.     subttl    --- constants, equates and data areas
  117.     page
  118.  
  119. bel    equ    7            ; honker
  120. bs    equ    8            ; backspace
  121. tab    equ    9            ; tabski
  122. lf    equ    10            ; Line Feed
  123. cr    equ    13            ; la Carriage Return
  124. eof    equ    26            ; end of file character
  125. stopper equ    255            ; ends print strings
  126.  
  127.     db    bs,bs,bs,'   '          ; overlay entry jmp for type
  128.  
  129. usage    db    cr,lf,     'ZIPV Version 1.07 Copyright (c) 1989 Vernon D. Buerg'
  130.     db    cr,lf,     'For personal use only. May not be sold.'
  131.     db    cr,lf,lf,'  Usage:  zipv [d:][\path\]filespec[.ZIP]  [/p] [/b] [/c]'
  132.     db    cr,lf
  133.     db    cr,lf,     '  Where:  /P pauses after each screenful'
  134.     db    cr,lf,     '          /B suppresses display of d:\path'
  135.     db    cr,lf,     '          /C displays comments'
  136.     db    cr,lf,stopper,eof
  137.  
  138. errlvl    db    0            ; dos error level returned
  139. opencod db    0            ; open code for share
  140. flags    db    255            ; find-first return code
  141.  
  142. options db    0            ; command options
  143. b_parm     equ    1            ; /b -bbs display option
  144. p_parm     equ    2            ; /p -pause at screen full
  145. c_parm     equ    4            ; /c - display comments
  146.  
  147. stkptr    dw    0            ; stack pointer upon entry
  148. ce_ptr    dw    0            ; offset to central_end dir record
  149. ce_count dw    0            ; count of entries in central dir
  150.  
  151. fileptr dw    filenm            ; spot after d:\path
  152. filehdl dw    0            ; file handle
  153.  
  154. ziptitl db    cr,lf,'Archive:  ',stopper
  155.  
  156. zipname db    13 dup (0),0,stopper    ; ZIP file name for heading
  157.  
  158. ;    display lines for verbose
  159.  
  160. vhdr    db    cr,lf
  161.     db    cr,lf,'Name          Length    Method     SF   Size now  Mod Date    Time    CRC-32 '
  162. dashes    db    cr,lf,'============  ========  ========  ====  ========  =========  ======  ========'
  163.     db    stopper
  164.  
  165. vline    db    cr,lf
  166. vname    db    14 dup (' ')
  167. vsize    db    '       0  '            ; acutal file size
  168. vstyle    db    '          '            ; compression method
  169. vfactor db    ' xx%  '                ; compression factor
  170. vlength db    10 dup (' ')            ; compressed length
  171. vdate    db    'dd '                   ; creation date
  172.  vmonth db    'mmm '
  173.  vyear    db    'yy  '
  174.  vtime    db    'hh:mm   '              ; creation time
  175.  vcrc    db    'xxxxxxxx'              ; crc in hex
  176.     db    stopper
  177. len_vline equ    $-vline         ; length of print line
  178.  
  179. totsf    dw    0,0            ; average stowage factor
  180. totlen    dw    0,0            ; total of file lengths
  181. totsize dw    0,0            ; total of file sizes
  182. totmbrs dw    0            ; total number of files
  183.  
  184. ;    final totals line
  185.  
  186. vthdr    db    cr,lf,'*total'
  187.  vtmbrs db    '        '
  188.  vtsize db    8 dup (' '),'  '
  189.     db    10 dup (' ')
  190.  vtsf    db    '   %  '
  191.  vtlen    db    8 dup (' ')
  192.     db    cr,lf
  193.     db    stopper
  194.  sign    db    ' '
  195.  
  196. vtotal    db    '*total'
  197. ctitle    db    cr,lf,'Comment:  ',stopper
  198. cextra    db    cr,lf,'Extra:    ',stopper
  199.  
  200. styles    db    'Stored  '              ; compression method names
  201.     db    'Shrunk  '
  202.     db    'Reduced1'
  203.     db    'Reduced2'
  204.     db    'Reduced3'
  205.     db    'Reduced4'
  206.  
  207. hundred dw    100            ; for computing percentages
  208. months    db    'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec '
  209.     subttl    --- Mainline
  210.     page
  211.  
  212. start:
  213.     mov    sp,offset cs:stk_end    ; local stack
  214.     mov    stkptr,sp        ; save for dos return
  215.  
  216.     mov    ah,30h            ; get dos version
  217.     int    21h            ;
  218.     cmp    al,2            ; version 2 or later?
  219.     jb    badver            ; no, gotta quit
  220.     cmp    al,3            ; enough for share?
  221.     jb    dos_okay        ; no, open as-is
  222.     mov    opencod,40h        ; yes, add read-only
  223.  
  224. dos_okay:
  225.     mov    bx,paras        ; size of program
  226.     mov    ah,4ah            ; shrink allocated memory
  227.     int    21h            ; setblock function
  228.  
  229.     mov    di,offset filenm    ; clear operands
  230.     mov    cx,offset stk-filenm    ;  and work areas
  231.     mov    al,0            ;
  232.     rep    stosb            ;
  233.  
  234.     subttl    --- gather command line parameters
  235.     page
  236.  
  237. getparm:
  238.     mov    si,82h            ; Command tail
  239.     sub    cx,cx            ;
  240.     or    cl,byte ptr -2[si]    ; test parm length
  241.     jz    getparms        ; none, return as-is
  242.  
  243. sw1:    lodsb                ; scan for switch
  244.     cmp    al,'/'                  ;
  245.     loopne    sw1            ;
  246.     or    cx,cx            ; found one?
  247.     jz    getparms        ; no, done
  248.     mov    byte ptr -1[si],cr    ; yes, stop command line there
  249.     jmp    sw2a            ; and check next character
  250.  
  251. sw2:    lodsb                ; Next character
  252.     cmp    al,'/'                  ; Another switch?
  253.     loopne    sw2            ;
  254.     jcxz    getparms        ;
  255.  
  256. sw2a:    lodsb                ; yes, get letter following
  257.     and    al,0dfh         ; make upper case
  258.     dec    cx            ;
  259.     jle    sw3            ; missing switch
  260.  
  261. sw3:    cmp    al,'P'                  ; Pause?
  262.     jne    sw4            ;
  263.     or    options,p_parm        ;
  264.  
  265. sw4:    cmp    al,'B'                  ; BBS use
  266.     jne    sw5            ;
  267.     or    options,b_parm        ;
  268.  
  269. sw5:    cmp    al,'C'                  ; display Comments?
  270.     jne    sw2            ;
  271.     or    options,c_parm        ;
  272.     jmp    sw2            ; Try for another option
  273.  
  274.     subttl    --- Gather command operands
  275.     page
  276.  
  277. ;    copy first command line operand as ZIP selection filespec
  278.  
  279. getparms:
  280.     mov    si,80h            ; offset to command line
  281.     sub    cx,cx            ; its length
  282.     or    cl,byte ptr [si]    ; any operand?
  283.     jnz    parm0            ; no,
  284.     print    usage            ;  display usage
  285.     jmp    zipv_exit        ;   and quit
  286.  
  287. parm0:    inc    si            ; point to operands
  288. parm2:    lodsb                ; strip leading blanks
  289.     cmp    al,' '                  ;
  290.     loope    parm2            ;
  291.  
  292.     mov    di,offset filenm    ; first operand target
  293.     stosb                ;
  294. parm3:    lodsb                ; copy filename